﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace DHISInteroperability.DataTransfer
{

    ///// <remarks/>
    //[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://dhis2.org/schema/dxf/2.0")]
    //[System.Xml.Serialization.XmlRootAttribute(Namespace = "http://dhis2.org/schema/dxf/2.0", IsNullable = false)]
    //public partial class dataValueSet
    //{

    //    private dataValue[] dataValueField;

    //    private string dataSetField;

    //    private string periodField;

    //    private string orgUnitField;

    //    /// <remarks/>
    //    [System.Xml.Serialization.XmlElementAttribute("dataValue")]
    //    public dataValue[] dataValue
    //    {
    //        get
    //        {
    //            return this.dataValueField;
    //        }
    //        set
    //        {
    //            this.dataValueField = value;
    //        }
    //    }

    //    /// <remarks/>
    //    [System.Xml.Serialization.XmlAttributeAttribute()]
    //    public string dataSet
    //    {
    //        get
    //        {
    //            return this.dataSetField;
    //        }
    //        set
    //        {
    //            this.dataSetField = value;
    //        }
    //    }

    //    /// <remarks/>
    //    [System.Xml.Serialization.XmlAttributeAttribute()]
    //    public string period
    //    {
    //        get
    //        {
    //            return this.periodField;
    //        }
    //        set
    //        {
    //            this.periodField = value;
    //        }
    //    }

    //    /// <remarks/>
    //    [System.Xml.Serialization.XmlAttributeAttribute()]
    //    public string orgUnit
    //    {
    //        get
    //        {
    //            return this.orgUnitField;
    //        }
    //        set
    //        {
    //            this.orgUnitField = value;
    //        }
    //    }
    //}

    /// <remarks/>
    [XmlTypeAttribute(AnonymousType = true, Namespace = "http://dhis2.org/schema/dxf/2.0")]
    [XmlRootAttribute(Namespace = "http://dhis2.org/schema/dxf/2.0", IsNullable = false)]
    public partial class dataValueSet
    {
        private dataValue[] dataValueField;

        private string dataSetField;

        private string completeDateField;

        private string periodField;

        private string orgUnitField;

        /// <remarks/>
        [XmlElementAttribute("dataValue")]
        public dataValue[] dataValue
        {
            get
            {
                return this.dataValueField;
            }
            set
            {
                this.dataValueField = value;
            }
        }

        /// <remarks/>
        [XmlAttributeAttribute]
        public string dataSet
        {
            get
            {
                return this.dataSetField;
            }
            set
            {
                this.dataSetField = value;
            }
        }

        /// <remarks/>
        [XmlAttributeAttribute]
        public string completeDate
        {
            get
            {
                return this.completeDateField;
            }
            set
            {
                this.completeDateField = value;
            }
        }

        /// <remarks/>
        [XmlAttributeAttribute]
        public string period
        {
            get
            {
                return this.periodField;
            }
            set
            {
                this.periodField = value;
            }
        }

        /// <remarks/>
        [XmlAttributeAttribute]
        public string orgUnit
        {
            get
            {
                return this.orgUnitField;
            }
            set
            {
                this.orgUnitField = value;
            }
        }

        public void SetCompleted(bool isCompleted = true)
        {
            if (isCompleted) completeDateField = DateTime.Now.ToString("o");
            else completeDateField = null;
        }

        public void SetCompleted(DateTime completeDate)
        {
            completeDateField = completeDate.ToString("o");
        }

        public void SetCompleted(string completeDate)
        {
            DateTime date = DateTime.Parse(completeDate);
            completeDateField = date.ToString("o");
        }
    }
}
